# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name：     rdb
   Description :
   Author :       zm.z
   date：          2020/2/3
-------------------------------------------------
   Change Activity:
                   2020/2/3:
-------------------------------------------------
"""
__author__ = 'zm.z'
import time
import json
import redis
import datetime

DNS = {
    "host":"120.79.19.42",
    "port":6444,
    "password":'iwnzslfiwdx',
}
class ToolRedis:

    def __init__(self):
        self.rdb = redis.Redis(**DNS)

    def get_cookies(self, key):
        pass

    def push(self, key, item):
        self.rdb.lpush(key, json.dumps(item))

    def pop(self, key, delay=0.5):

        item = self.rdb.rpop(key)
        if item is None:
            return
        time.sleep(delay)
        return json.loads(item.decode())

    def set_with_today(self, key):
        self.rdb.set(key, 1)
        today = datetime.datetime.now()
        dt = datetime.datetime(year=today.year, month=today.month, day=today.day+1)
        self.rdb.expireat(key, dt)

    def get(self, key):
        return self.rdb.get(key)